/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * Description: Hmfs-tools mkfs multi unit test
 */

#include "gtest/gtest.h"

#include <cstdio>
#include <cstdlib>
#include <errno.h>
#include <fcntl.h>
#include <fstream>
#include <numeric>
#include <unistd.h>

#include "compare.h"
#include "whole_compare.h"
#include "hmfs_test_utils.h"
#include "mkfs_command_parser.h"

using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Hmfs {
const std::string STDOUT_OUTPUT_FILE_PATH = "/data/local/";
constexpr uint32_t LOOP_NUM = 2000;

class MkfsHmfsMultiTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;
    static std::vector<std::string> ConstructCombinationParameters(const std::string &optionGroup,
        const bool containReadOnly = false, const bool changePath = false);
    static void ClearTestFile();
};

void MkfsHmfsMultiTest::SetUpTestCase()
{
    system("mount -o remount,rw /");
    system("ln -s /bin/fsck.f2fs /bin/dump.f2fs");
    (void)MkfsCmdParser::GetInstance();
}

void MkfsHmfsMultiTest::TearDownTestCase()
{
    system("rm -rf /system/bin/dump.f2fs");
}

void MkfsHmfsMultiTest::SetUp()
{
    for (uint8_t i = 0; i < 4; i++) {
        DataDuplicatorDevice(HMFS_DEVICE_PATH_LIST[i]);
        DataDuplicatorDevice(F2FS_DEVICE_PATH_LIST[i]);
    }
    system("sleep 10");
}

void MkfsHmfsMultiTest::TearDown()
{
    system("rm -rf /data/local/hmfs* /data/local/f2fs*");
}

void MkfsHmfsMultiTest::ClearTestFile()
{
    for (uint8_t i = 0; i < MAX_DEVICE_COUNTS; i++) {
        ClearFile(F2FS_DEVICE_PATH_LIST[i]);
        ClearFile(HMFS_DEVICE_PATH_LIST[i]);
    }
}

std::vector<std::string> MkfsHmfsMultiTest::ConstructCombinationParameters(const std::string &optionGroup,
    const bool containReadOnly, const bool changePath)
{
    std::vector<std::string> params;
    params.emplace_back("-a 1");
    params.emplace_back("-d 1");

    if (optionGroup.find("-e") != std::string::npos) {
        params.emplace_back("-e cool");
    }

    if (optionGroup.find("-E") != std::string::npos) {
        params.emplace_back("-E hot");
    }

    params.emplace_back("-i");

    if (optionGroup.find("-m") != std::string::npos) {
        params.emplace_back("-m");
    }

    params.emplace_back("-C");
    params.emplace_back("utf8");
    params.emplace_back("-r");
    params.emplace_back("-R 1000:1000");
    params.emplace_back("-s 2");
    params.emplace_back("-t 1");
    params.emplace_back("-T 10086");

    params.emplace_back("-z 2");

    if (optionGroup.find("-O") != std::string::npos) {
        std::string defaultList("-O inode_checksum,flexible_inline_xattr,inode_crtime,lost_found,casefold,"
            "verity,quota,encrypt,sb_checksum,extra_attr,project_quota,compression");
        defaultList += containReadOnly ? ",ro" : "";
        params.emplace_back(defaultList);
    }

    bool contaionWantSecSize = optionGroup.find("-w") != std::string::npos;
    if (contaionWantSecSize) {
        params.emplace_back("-l hmfsTestLablew");
        params.emplace_back("-w 1024");
        if (optionGroup.find("-o") != std::string::npos) {
            params.emplace_back("-o 50");
        }
    }

    if (optionGroup.find("-c") != std::string::npos) {
        params.emplace_back("-l hmfsTestLablec");

        if (optionGroup.find("-o") != std::string::npos) {
            params.emplace_back("-o 20");
        }

        if (changePath) {
            params.emplace_back("-c");
            params.emplace_back(F2FS_DEVICE_PATH_LIST[1]);
            params.emplace_back("-c");
            params.emplace_back(F2FS_DEVICE_PATH_LIST[2]);
            params.emplace_back("-c");
            params.emplace_back(F2FS_DEVICE_PATH_LIST[3]);
        } else {
            params.emplace_back("-c");
            params.emplace_back(HMFS_DEVICE_PATH_LIST[1]);
            params.emplace_back("-c");
            params.emplace_back(HMFS_DEVICE_PATH_LIST[2]);
            params.emplace_back("-c");
            params.emplace_back(HMFS_DEVICE_PATH_LIST[3]);
        }
    }

    params.emplace_back(changePath ? F2FS_DEVICE_PATH_LIST[0] : HMFS_DEVICE_PATH_LIST[0]);

    if (contaionWantSecSize) {
        params.emplace_back("150000");
    }

    PrintParameters(params);
    return params;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_001
 * @tc.desc: Test the combination parameters, including the -c option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_001, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_001 Begin" << std::endl;
    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-e-o-O-c", false, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-e-o-O-c", false, false);
    std::string hmfsDevice =  HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    fsckRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_001 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_002
 * @tc.desc: Test the combination parameters, including the -c option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_002, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_002 Begin" << std::endl;

    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-e-O-c", true, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-e-O-c", true, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_001 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_003
 * @tc.desc: Test the combination parameters, including the -c option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_003, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_003 Begin" << std::endl;
    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-E-O-c", false, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-E-O-c", false, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_003 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_004
 * @tc.desc: Test the combination parameters, including the -c option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_004, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_004 Begin" << std::endl;
    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-E-O-c", true, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-E-O-c", true, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_004 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_005
 * @tc.desc: Test the combination parameters, including the -c option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_005, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_005 Begin" << std::endl;
    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-e-c", false, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-e-c", false, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_005 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_006
 * @tc.desc: Test the combination parameters, including the -w option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_006, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_006 Begin" << std::endl;
    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-e-O-w", false, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-e-O-w", false, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_006 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_007
 * @tc.desc: Test the combination parameters, including the -w option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_007, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_007 Begin" << std::endl;
    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-e-O-w", true, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-e-O-w", true, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_007 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_008
 * @tc.desc: Test the combination parameters, including the -w option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_008, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_008 Begin" << std::endl;

    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-E-O-w", false, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-E-O-w", false, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_008 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_009
 * @tc.desc: Test the combination parameters, including the -w option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_009, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_009 Begin" << std::endl;

    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-E-O-w", true, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-E-O-w", true, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_009 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_010
 * @tc.desc: Test the combination parameters, including the -w option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_010, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_010 Begin" << std::endl;

    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-e-w", false, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(0, f2fsRes);
    bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevice);
    ASSERT_TRUE(fsckF2fsRes);

    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    GetCheckPoint(f2fsDevice, f2fsCheckPoint);
    GetSuperBlock(f2fsDevice, f2fsSuperBlock);
    auto f2fsNodeData = std::make_unique<NodeData>();
    int16_t f2fsAddrIndex = -1;
    GetInodeInfo(f2fsDevice, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-e-w", false, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(0, hmfsRes);
    bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevice);
    ASSERT_TRUE(fsckHmfsRes);

    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    GetCheckPoint(hmfsDevice, hmfsCheckPoint);
    GetSuperBlock(hmfsDevice, hmfsSuperBlock);
    auto hmfsNodeData = std::make_unique<NodeData>();
    int16_t hmfsAddrIndex = -1;
    GetInodeInfo(hmfsDevice, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

    ASSERT_EQ(hmfsAddrIndex, f2fsAddrIndex);
    SuperBlockCode compSB = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
    ASSERT_EQ(SUCCESSED_SB, compSB);
    CheckPointCode compCP = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
    ASSERT_EQ(SUCCESSED_CP, compCP);
    NodeDataCode compND = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
    ASSERT_EQ(SUCCESSED_ND, compND);
    ASSERT_EQ(FsBinaryCompare(f2fsDevice, hmfsDevice), 0);
    ASSERT_EQ(FsResultCompare(f2fsDevice, hmfsDevice), 0);
    (void)CompareRunTime(f2fsRunTime, hmfsRunTime);
    std::cout << "MkfsHmfsTest_Combination_010 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_011
 * @tc.desc: Test the combination parameters, including the -w -c option.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_011, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_011 Begin" << std::endl;

    std::vector<std::string> f2fsComParameters = ConstructCombinationParameters("-e-O-w-c", false, true);
    std::string f2fsDevice = F2FS_DEVICE_PATH_LIST[0];
    uint64_t f2fsRunTime = 0;
    int32_t f2fsRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevice, f2fsComParameters, f2fsRunTime);
    ASSERT_EQ(1, f2fsRes);

    std::vector<std::string> hmfsComParameters = ConstructCombinationParameters("-e-O-w-c", false, false);
    std::string hmfsDevice = HMFS_DEVICE_PATH_LIST[0];
    uint64_t hmfsRunTime = 0;
    int32_t hmfsRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevice, hmfsComParameters, hmfsRunTime);
    ASSERT_EQ(255, hmfsRes);
    std::cout << "MkfsHmfsTest_Combination_011 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Combination_Random_012
 * @tc.desc: The test parameter options are random and the parameter option values are also random.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Combination_Random_012, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Combination_Random_012 Begin" << std::endl;
    for (uint8_t i = 4; i < MAX_DEVICE_COUNTS; i++) {
        DataDuplicatorDevice(HMFS_DEVICE_PATH_LIST[i]);
        DataDuplicatorDevice(F2FS_DEVICE_PATH_LIST[i]);
    }

    std::srand(std::time(nullptr));
    std::vector<std::string> f2fsComParameters;
    std::vector<std::string> hmfsComParameters;
    for (uint32_t i = 0; i < LOOP_NUM; ++i) {
        f2fsComParameters.clear();
        hmfsComParameters.clear();
        f2fsComParameters = GenerateParams(false);
        hmfsComParameters = f2fsComParameters;
        ReplaceDevicePaths(hmfsComParameters);
        PrintParameters(hmfsComParameters);

        std::map<std::string, std::string> parameterMap{};
        if(!CheckParametersVaild(f2fsComParameters, parameterMap)){
            ClearTestFile();
            continue;
        }

        std::string f2fsDevicePath = F2FS_DEVICE_PATH_LIST[MAX_DEVICE_COUNTS - 1];
        std::string hmfsDevicePath = HMFS_DEVICE_PATH_LIST[MAX_DEVICE_COUNTS - 1];
        std::cout << "Random_012_" << i << " f2fsDevicePath : " << f2fsDevicePath << std::endl;
        std::cout << "Random_012_" << i << " hmfsDevicePath : " << hmfsDevicePath << std::endl;

        uint64_t f2fsRunTime = 0;
        uint64_t hmfsRunTime = 0;
        int32_t f2fsExeRes = ExecMkfsBinary(F2FS_TYPE, f2fsDevicePath, f2fsComParameters, f2fsRunTime);
        int32_t hmfsExeRes = ExecMkfsBinary(HMFS_TYPE, hmfsDevicePath, hmfsComParameters, hmfsRunTime);
        std::cout << "i : " << i << " f2fsExeRes = " << f2fsExeRes << " hmfsExeRes = " << hmfsExeRes << std::endl;
        if ((f2fsExeRes != 0 && hmfsExeRes != 0)) {
            ClearTestFile();
            continue;
        }

        bool fsckF2fsRes = ExecFsckBinaryAndCheck(f2fsDevicePath);
        ASSERT_TRUE(fsckF2fsRes);

        bool fsckHmfsRes = ExecFsckBinaryAndCheck(hmfsDevicePath);
        ASSERT_TRUE(fsckHmfsRes);

        auto f2fsCheckPoint = std::make_unique<CheckPointData>();
        auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
        auto f2fsNodeData = std::make_unique<NodeData>();
        GetSuperBlock(f2fsDevicePath, f2fsSuperBlock);
        GetCheckPoint(f2fsDevicePath, f2fsCheckPoint);
        int16_t f2fsAddrIndex = -1;
        GetInodeInfo(f2fsDevicePath, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));
        uint32_t f2fsFeatures = GetLeValue(f2fsSuperBlock->features);
        PrintInodeInfo(f2fsFeatures, f2fsNodeData, f2fsAddrIndex, GetLeValue(f2fsSuperBlock->rootInodeId));

        auto hmfsCheckPoint = std::make_unique<CheckPointData>();
        auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
        auto hmfsNodeData = std::make_unique<NodeData>();
        GetSuperBlock(hmfsDevicePath, hmfsSuperBlock);
        GetCheckPoint(hmfsDevicePath, hmfsCheckPoint);
        int16_t hmfsAddrIndex = -1;
        GetInodeInfo(hmfsDevicePath, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));
        uint32_t hmfsFeatures = GetLeValue(hmfsSuperBlock->features);
        PrintInodeInfo(hmfsFeatures, hmfsNodeData, hmfsAddrIndex, GetLeValue(hmfsSuperBlock->rootInodeId));

        bool mkfsF2fsRes = CheckMkfsHmfsResult(parameterMap, f2fsCheckPoint, f2fsSuperBlock, f2fsNodeData);
        bool mkfsHmfsRes = CheckMkfsHmfsResult(parameterMap, hmfsCheckPoint, hmfsSuperBlock, hmfsNodeData);
        if ((!mkfsF2fsRes) || (!mkfsHmfsRes)) {
            EXPECT_TRUE(false);
            break;
        }

        SuperBlockCode supBlkCode = CompareSuperBlock(f2fsSuperBlock, hmfsSuperBlock);
        CheckPointCode chkPointCode = CompareCheckPoint(f2fsCheckPoint, hmfsCheckPoint);
        ASSERT_EQ(supBlkCode, SUCCESSED_SB);
        ASSERT_EQ(chkPointCode, SUCCESSED_CP);
        ASSERT_EQ(f2fsAddrIndex, hmfsAddrIndex);

        std::vector<std::string>::const_iterator iter = std::find(f2fsComParameters.begin(),
            f2fsComParameters.end(), "-T");
        NodeDataCode nodeDataCode = ERROR_NODE_UNKNOWN;
        if (iter != f2fsComParameters.end()) {
            nodeDataCode = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, true);
        } else {
            nodeDataCode = CompareNodeData(f2fsNodeData, hmfsNodeData, f2fsAddrIndex, false);
        }
        ASSERT_EQ(nodeDataCode, SUCCESSED_ND);
        ASSERT_EQ(FsBinaryCompare(f2fsDevicePath, hmfsDevicePath), 0);
        ASSERT_EQ(FsResultCompare(f2fsDevicePath, hmfsDevicePath), 0);
        ClearTestFile();
    }
    std::cout << "MkfsHmfsTest_Combination_Random_012 End" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Abnormal_001
 * @tc.desc: Test for abnormal exit during the execution of the mkfs command.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Abnormal_001, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Abnormal_001 BEGIN" << std::endl;

    std::string device = F2FS_DEVICE_PATH_LIST[0];
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("extra_attr,project_quota");
    params.push_back("-w");
    params.push_back("2048");
    params.push_back(device);
    params.push_back("150000");
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    uint64_t f2fsRunTime = 0;

    pid_t pid = fork();
    if (pid < 0) {
        assert(pid > 0 && "fork failed with errno = " + std::to_string(errno));
    }
    if (pid == 0) {
        pid_t childId = getpid();
        std::cout << "PID: " << childId << std::endl;
        ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device, params, f2fsRunTime));
        sleep(10);
    }

    while (true) {
        GetCheckPoint(device, f2fsCheckPoint);
        if (f2fsCheckPoint->overprovisionSegmentCount == 22) {
            kill(pid, SIGKILL);
            std::cout << "Child process terminated" << std::endl;
            break;
        }
    }
    int status;
    pid_t resid = waitpid(pid, &status, 0);
    std::cout << "resid: " << resid << std::endl;

    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device, params, f2fsRunTime));
    bool fsckRes = ExecFsckBinaryAndCheck(device);
    EXPECT_TRUE(fsckRes);

    std::cout << "MkfsHmfsTest_Abnormal_001 END" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Abnormal_002
 * @tc.desc: Test for abnormal exit during the execution of the mkfs command.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Abnormal_002, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Abnormal_002 BEGIN" << std::endl;

    std::string hmdevice = HMFS_DEVICE_PATH_LIST[0];
    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("extra_attr,project_quota");
    params.push_back("-w");
    params.push_back("2048");
    params.push_back(hmdevice);
    params.push_back("150000");
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    uint64_t hmfsRunTime = 0;

    pid_t pid = fork();
    if (pid < 0) {
        assert(pid > 0 && "fork failed with errno = " + std::to_string(errno));
    }
    if (pid == 0) {
        pid_t childId = getpid();
        std::cout << "PID: " << childId << std::endl;
        ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmdevice, params, hmfsRunTime));
        sleep(10);
    }

    while (true) {
        GetCheckPoint(hmdevice, hmfsCheckPoint);
        if (hmfsCheckPoint->overprovisionSegmentCount == 22) {
            kill(pid, SIGKILL);
            std::cout << "Child process terminated" << std::endl;
            break;
        }
    }
    int status;
    pid_t resid = waitpid(pid, &status, 0);
    std::cout << "resid: " << resid << std::endl;

    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmdevice, params, hmfsRunTime));

    bool fsckRes = ExecFsckBinaryAndCheck(hmdevice);
    EXPECT_TRUE(fsckRes);
    std::cout << "MkfsHmfsTest_Abnormal_002 END" << std::endl;
}

/*
 * @tc.name: MkfsHmfsTest_Abnormal_003
 * @tc.desc: Test for abnormal exit during the execution of the mkfs command.
 * @tc.type: FUNC
 */
HWTEST_F(MkfsHmfsMultiTest, MkfsHmfsTest_Abnormal_003, TestSize.Level1)
{
    std::cout << "MkfsHmfsTest_Abnormal_003 BEGIN" << std::endl;
    std::string device = F2FS_DEVICE_PATH_LIST[0];
    auto f2fsSuperBlock = std::make_unique<SuperBlockData>();
    auto f2fsCheckPoint = std::make_unique<CheckPointData>();
    std::string hmdevice = HMFS_DEVICE_PATH_LIST[0];
    auto hmfsSuperBlock = std::make_unique<SuperBlockData>();
    auto hmfsCheckPoint = std::make_unique<CheckPointData>();
    uint64_t f2fsRunTime = 0;
    uint64_t hmfsRunTime = 0;

    std::vector<std::string> params;
    params.clear();
    params.push_back("-O");
    params.push_back("extra_attr,project_quota");
    params.push_back("-w");
    params.push_back("2048");
    params.push_back(device);
    params.push_back("150000");
    pid_t pid = fork();
    if (pid < 0) {
        assert(pid > 0 && "fork failed with errno = " + std::to_string(errno));
    }
    if (pid == 0) {
        pid_t childId = getpid();
        std::cout << "PID: " << childId << std::endl;
        ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device, params, f2fsRunTime));
        sleep(10);
    }

    while (true) {
        GetCheckPoint(device, f2fsCheckPoint);
        if (f2fsCheckPoint->overprovisionSegmentCount == 22) {
            kill(pid, SIGKILL);
            std::cout << "Child process terminated" << std::endl;
            break;
        }
    }
    int status = 0;
    pid_t f2fsPid = waitpid(pid, &status, 0);
    std::cout << "success2kill: " << f2fsPid << std::endl;
    uint32_t f2fsOverproSegmentCount = f2fsCheckPoint->overprovisionSegmentCount;

    params.clear();
    params.push_back("-O");
    params.push_back("extra_attr,project_quota");
    params.push_back("-w");
    params.push_back("2048");
    params.push_back(hmdevice);
    params.push_back("150000");
    pid_t pidHmfs = fork();
    if (pidHmfs < 0) {
        assert(pidHmfs > 0 && "fork failed with errno = " + std::to_string(errno));
    }
    if (pidHmfs == 0) {
        pid_t childId = getpid();
        std::cout << "PID: " << childId << std::endl;
        ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmdevice, params, hmfsRunTime));
        sleep(10);
    }

    while (true) {
        GetCheckPoint(hmdevice, hmfsCheckPoint);
        if (hmfsCheckPoint->overprovisionSegmentCount == 22) {
            kill(pidHmfs, SIGKILL);
            std::cout << "Child process terminated" << std::endl;
            break;
        }
    }
    pid_t hmfsPid = waitpid(pidHmfs, &status, 0);
    std::cout << "success2kill: " << hmfsPid << std::endl;
    uint32_t hmfsOverproSegmentCount = hmfsCheckPoint->overprovisionSegmentCount;

    ASSERT_EQ(f2fsOverproSegmentCount, hmfsOverproSegmentCount);
    ASSERT_EQ(0, ExecMkfsBinary(F2FS_TYPE, device, params, f2fsRunTime));
    ASSERT_EQ(0, ExecMkfsBinary(HMFS_TYPE, hmdevice, params, hmfsRunTime));

    bool f2fsFsckRes = ExecFsckBinaryAndCheck(device);
    EXPECT_TRUE(f2fsFsckRes);
    bool hmfsFsckRes = ExecFsckBinaryAndCheck(hmdevice);
    EXPECT_TRUE(hmfsFsckRes);

    std::cout << "MkfsHmfsTest_Abnormal_003 END" << std::endl;
}
} // namespace Hmfs
} // namespace OHOS